package ar.com.spsolutions.splibrary.author;

import java.util.HashSet;
import java.util.Set;

import ar.com.spsolutions.splibrary.book.Book;
import ar.com.spsolutions.splibrary.entity.Entity;

public class Author extends Entity {

	private static final long serialVersionUID = -404357880457194301L;

	private String name;

	private Set<Book> books = new HashSet<Book>();

	public Author(final String string) {
		super();
		this.name = string;
	}

	public Author() {
		super();
	}

	public String getName() {
		return this.name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public void addBook(final Book book) {
		this.getBooks().add(book);
	}

	public Set<Book> getBooks() {
		return this.books;
	}

	public void setBooks(final Set<Book> books) {
		this.books = books;
	}

	public void removeBook(final Book book) {
		this.getBooks().remove(book);
	}

	@Override
	public String toString() {
		return this.name;
	}

	@Override
	public int hashCode() {
		int result = 1;
		result = (31 * result)
				+ ((this.name == null) ? 0 : this.name.hashCode());
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (this.getClass() != obj.getClass()) {
			return false;
		}
		final Author other = (Author) obj;
		if (this.name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!this.name.equals(other.name)) {
			return false;
		}
		return true;
	}

}
